import vars

class buddy:
    name = ""
    group = ""
    iid = ""
    allow = True
    warning = 0
    status = 0
    message = ""

    def __init__(self):
        self.name = ""
        self.group = ""
        self.allow = True
        self.warning = 0

    def __init__(self, nm, gr, id="0"):
        self.name = nm
        self.group = gr
        self.iid = int(id)


    def __str__(self):
        if self.status == 1:
            state = ""
        if self.status == 0:
            state = ""
        if self.status == 2:
            state = "(Away)"
            
        output =  self.name + state 
        if len(self.message) > 0:
            output += ': ' + self.message 
        return output


class group:
    name = ""
    id = ""
    members = []
    visible = True

    def __init__(self):
        self.name =""
        self.members = []
    
    def __init__(self, name, id):
        self.name = name
        self.id = id
        self.members = []

    def add(self, buddy):
        self.members.append(buddy)

    def __str__(self):
        counton = 0
        count = 0
        buddies = ""
        if self.visible:
            if self.name == "Offline Buddies":
                count = 0
                for i in vars.buddyList:
                    if i.status == 0:
                        count = count + 1
                        buddies = buddies + '\t'+str(i) +'\n' 
            elif not len(self.name) == 0:
                for i in vars.buddyList:
                    if self.id == i.group:
                        count = count + 1
                        if i.status >= 1:
                            counton = counton + 1
                            buddies=buddies + '\t'+str(i)+'\n'



        return self.name + '(' + str(counton) + '/' + str(count) + ")"

def getBuddy(name):

    for ii in vars.buddyList:
        if ii.name == name:
            return True, ii
        
    return False, None
        
